﻿namespace Socket.Core
{
    using System;
    using System.Net.Sockets;

    internal sealed class SocketAsyncEventArgsPool
    {
        private readonly LockFreeStack<SocketAsyncEventArgs> pool = new LockFreeStack<SocketAsyncEventArgs>();

        internal SocketAsyncEventArgsPool(int capacity)
        {
        }

        internal SocketAsyncEventArgs Pop()
        {
            return this.pool.Pop();
        }

        internal void Push(SocketAsyncEventArgs item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("Items added to a SocketAsyncEventArgsPool cannot be null");
            }
            this.pool.Push(item);
        }

        internal long Count
        {
            get
            {
                return this.pool.Count;
            }
        }
    }
}

